/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Cartera_y_caja;

import inmobiliaria_fase01.Conexion;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Usuario
 */
public class Recibos_Caja extends javax.swing.JDialog {

   private DefaultTableModel modeloDeMiJTable; 
    
    public Recibos_Caja(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setSize(920,600);
        setLocationRelativeTo(rootPane);
        modeloDeMiJTable = new DefaultTableModel() { 
        @Override 
        public Class getColumnClass(int c) { 
        return getValueAt(0, c).getClass(); 
        } 

        @Override 
        public boolean isCellEditable(int rowIndex, int columnIndex) { 
        return false; 
        }

        };
        
        modeloDeMiJTable.addColumn("Cod");
        modeloDeMiJTable.addColumn("Concepto");
        modeloDeMiJTable.addColumn("No Cheque");
        modeloDeMiJTable.addColumn("Concepto");
        modeloDeMiJTable.addColumn("Valor");
        modeloDeMiJTable.addColumn("NIT");
        jTable1.setModel(modeloDeMiJTable);
        int[] anchos = {30, 70, 30,200,50,30};
        for(int i = 0; i < jTable1.getColumnCount(); i++) {

            //Sacamos el modelo de columnas de nuestra tabla

            //luego obtenemos la columna en la posicion "i"

            //invocamos el metodo setPreferrefWidth para ajustar el ancho

            //y le damos el valor del entero que esta en el arreglo en la posicion "i"

            jTable1.getColumnModel().getColumn(i).setPreferredWidth(anchos[i]);
            jButton_confirmar.setVisible(false);
            inicializar(false, false);
        }
        buscar_CONCEPTOS();
        jButton_confirmar1.setVisible(false);
    }
    private void inicializar(Boolean a, Boolean b){
        jPanel2.setVisible(a);
        jPanel1.setVisible(b);

    }
    private void panelrecibo(Boolean a){
        jRadioButton_cheque.setEnabled(a);
        jRadioButton_efectivo.setEnabled(a);
        jRadioButton_externo.setEnabled(a);
        jRadioButton_interno.setEnabled(a);
        jTextField_concepto.setEnabled(a);
        jTextField_valor.setEnabled(a);
        jComboBox_codigo.setEnabled(a);
        jComboBox_nit.setEnabled(a);
        jButton_confirmar.setEnabled(a);
        jCheckBox1.setEnabled(a);
    }
    private void panelcliente(Boolean a,Boolean b,Boolean c,Boolean d,Boolean e){
        jComboBox_destino.setEnabled(a);
        jTextField_codigo.setEnabled(b);
        jTextField_nombre.setEnabled(c);
        jTextField_direccion.setEnabled(d);
        jTextField_saldo.setEnabled(e);
    }
    private void botones (Boolean a,Boolean b,Boolean c,Boolean d){
        jButton_nuevo.setSelected(a);
        jButton_bucar.setSelected(b);
        jButton_imprimir.setSelected(c);
        jButton_informes.setSelected(d);
    }
public void buscar_CONCEPTOS(){
        Vector concepto = new Vector();
        try{
         conn.establecer_conexion();
         String sql="select nombres from conceptos";
         ResultSet resultado = conn.consulta(sql);
         concepto.addElement("Seleccione Concepto");
         while(resultado.next()){
             concepto.addElement(resultado.getString(1));
         }
        jComboBox_codigo.setModel(new javax.swing.DefaultComboBoxModel(concepto));
        }catch(Exception e){
            
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        extint = new javax.swing.ButtonGroup();
        efecheque = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jButton_nuevo = new javax.swing.JButton();
        jButton_informes = new javax.swing.JButton();
        jButton_bucar = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jButton_imprimir = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jTextField_concepto = new javax.swing.JTextField();
        jComboBox_nit = new javax.swing.JComboBox();
        jTextField_valor = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jRadioButton_interno = new javax.swing.JRadioButton();
        jRadioButton_externo = new javax.swing.JRadioButton();
        jRadioButton_cheque = new javax.swing.JRadioButton();
        jRadioButton_efectivo = new javax.swing.JRadioButton();
        jCheckBox1 = new javax.swing.JCheckBox();
        jComboBox_codigo = new javax.swing.JComboBox();
        jButton_confirmar = new javax.swing.JButton();
        jLabel19 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jTextField_codigo = new javax.swing.JTextField();
        jComboBox_destino = new javax.swing.JComboBox();
        jTextField_nombre = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jTextField_direccion = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        jTextField_saldo = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton_confirmar1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(null);

        jLabel1.setFont(new java.awt.Font("Segoe UI", 0, 36)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Recibo de Caja");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(0, 0, 260, 50);

        jButton_nuevo.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jButton_nuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/1396514185_Add.png"))); // NOI18N
        jButton_nuevo.setText("Nuevo");
        jButton_nuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_nuevoActionPerformed(evt);
            }
        });
        getContentPane().add(jButton_nuevo);
        jButton_nuevo.setBounds(270, 20, 150, 50);

        jButton_informes.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jButton_informes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/1396514254_Copy v2.png"))); // NOI18N
        jButton_informes.setText("Informes");
        jButton_informes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_informesActionPerformed(evt);
            }
        });
        getContentPane().add(jButton_informes);
        jButton_informes.setBounds(720, 20, 150, 50);

        jButton_bucar.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jButton_bucar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/1396514242_Search.png"))); // NOI18N
        jButton_bucar.setText("Buscar");
        jButton_bucar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_bucarActionPerformed(evt);
            }
        });
        getContentPane().add(jButton_bucar);
        jButton_bucar.setBounds(420, 20, 150, 50);

        jLabel9.setFont(new java.awt.Font("Segoe UI", 0, 20)); // NOI18N
        jLabel9.setText("Fecha: 27/04/2014");
        getContentPane().add(jLabel9);
        jLabel9.setBounds(30, 80, 200, 40);

        jButton_imprimir.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jButton_imprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/1398654205_printer.png"))); // NOI18N
        jButton_imprimir.setText("Imprimir");
        jButton_imprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_imprimirActionPerformed(evt);
            }
        });
        getContentPane().add(jButton_imprimir);
        jButton_imprimir.setBounds(570, 20, 150, 50);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2, true), "Detalle Recibo", 3, 0, new java.awt.Font("Segoe UI", 0, 20))); // NOI18N
        jPanel1.setLayout(null);

        jLabel14.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        jLabel14.setText("Codigo");
        jPanel1.add(jLabel14);
        jLabel14.setBounds(10, 150, 50, 30);

        jLabel15.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        jLabel15.setText("Recibo N°");
        jPanel1.add(jLabel15);
        jLabel15.setBounds(10, 20, 80, 40);
        jPanel1.add(jTextField_concepto);
        jTextField_concepto.setBounds(90, 90, 360, 30);

        jComboBox_nit.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione NIT", "Arrendatario", "Propietario", "Otro" }));
        jPanel1.add(jComboBox_nit);
        jComboBox_nit.setBounds(90, 180, 210, 30);
        jPanel1.add(jTextField_valor);
        jTextField_valor.setBounds(90, 120, 210, 30);

        jLabel16.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        jLabel16.setText("Valor");
        jPanel1.add(jLabel16);
        jLabel16.setBounds(10, 120, 60, 30);

        jLabel17.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        jLabel17.setText("NIT");
        jPanel1.add(jLabel17);
        jLabel17.setBounds(10, 180, 60, 30);

        extint.add(jRadioButton_interno);
        jRadioButton_interno.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jRadioButton_interno.setForeground(new java.awt.Color(0, 0, 204));
        jRadioButton_interno.setText("Interno");
        jPanel1.add(jRadioButton_interno);
        jRadioButton_interno.setBounds(110, 60, 90, 30);

        extint.add(jRadioButton_externo);
        jRadioButton_externo.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jRadioButton_externo.setForeground(new java.awt.Color(0, 0, 204));
        jRadioButton_externo.setText("Externo");
        jPanel1.add(jRadioButton_externo);
        jRadioButton_externo.setBounds(10, 60, 100, 29);

        efecheque.add(jRadioButton_cheque);
        jRadioButton_cheque.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jRadioButton_cheque.setForeground(new java.awt.Color(0, 153, 0));
        jRadioButton_cheque.setText("Cheque");
        jPanel1.add(jRadioButton_cheque);
        jRadioButton_cheque.setBounds(350, 60, 90, 29);

        efecheque.add(jRadioButton_efectivo);
        jRadioButton_efectivo.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        jRadioButton_efectivo.setForeground(new java.awt.Color(0, 153, 0));
        jRadioButton_efectivo.setText("Efectivo");
        jPanel1.add(jRadioButton_efectivo);
        jRadioButton_efectivo.setBounds(240, 60, 100, 29);

        jCheckBox1.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
        jCheckBox1.setText("Usar Saldo?");
        jCheckBox1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });
        jPanel1.add(jCheckBox1);
        jCheckBox1.setBounds(300, 120, 150, 30);

        jComboBox_codigo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione Codigo Concepto", "Arrendatario", "Propietario", "Otro" }));
        jPanel1.add(jComboBox_codigo);
        jComboBox_codigo.setBounds(90, 150, 210, 30);

        jButton_confirmar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/confirm.png"))); // NOI18N
        jButton_confirmar.setText("Añadir Registro");
        jButton_confirmar.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        jButton_confirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_confirmarActionPerformed(evt);
            }
        });
        jPanel1.add(jButton_confirmar);
        jButton_confirmar.setBounds(310, 180, 150, 30);

        jLabel19.setFont(new java.awt.Font("Segoe UI", 1, 24)); // NOI18N
        jLabel19.setForeground(new java.awt.Color(153, 0, 0));
        jLabel19.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel19.setText("CI054");
        jPanel1.add(jLabel19);
        jLabel19.setBounds(90, 20, 140, 40);

        jLabel18.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        jLabel18.setText("Concepto");
        jPanel1.add(jLabel18);
        jLabel18.setBounds(10, 90, 60, 30);

        getContentPane().add(jPanel1);
        jPanel1.setBounds(410, 110, 470, 230);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2, true), "Detalle Persona", 3, 0, new java.awt.Font("Segoe UI", 0, 20))); // NOI18N
        jPanel2.setLayout(null);

        jLabel20.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        jLabel20.setText("Destino");
        jPanel2.add(jLabel20);
        jLabel20.setBounds(10, 60, 50, 30);

        jLabel21.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        jLabel21.setText("Codigo");
        jPanel2.add(jLabel21);
        jLabel21.setBounds(10, 90, 60, 30);

        jTextField_codigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField_codigoActionPerformed(evt);
            }
        });
        jPanel2.add(jTextField_codigo);
        jTextField_codigo.setBounds(70, 90, 210, 30);

        jComboBox_destino.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione", "Arrendatario", "Propietario", "Otro" }));
        jComboBox_destino.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox_destinoItemStateChanged(evt);
            }
        });
        jPanel2.add(jComboBox_destino);
        jComboBox_destino.setBounds(70, 60, 160, 30);
        jPanel2.add(jTextField_nombre);
        jTextField_nombre.setBounds(70, 120, 260, 30);

        jLabel22.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        jLabel22.setText("Nombre");
        jPanel2.add(jLabel22);
        jLabel22.setBounds(10, 120, 60, 30);
        jPanel2.add(jTextField_direccion);
        jTextField_direccion.setBounds(70, 150, 260, 30);

        jLabel23.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        jLabel23.setText("Dirección");
        jPanel2.add(jLabel23);
        jLabel23.setBounds(10, 150, 60, 30);
        jPanel2.add(jTextField_saldo);
        jTextField_saldo.setBounds(70, 180, 260, 30);

        jLabel24.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
        jLabel24.setText("Saldo");
        jPanel2.add(jLabel24);
        jLabel24.setBounds(10, 180, 60, 30);

        getContentPane().add(jPanel2);
        jPanel2.setBounds(20, 110, 370, 230);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(10, 350, 880, 120);

        jButton_confirmar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/confirm.png"))); // NOI18N
        jButton_confirmar1.setText("GUARDAR RECIBO");
        jButton_confirmar1.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        jButton_confirmar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_confirmar1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton_confirmar1);
        jButton_confirmar1.setBounds(700, 480, 190, 40);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_nuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_nuevoActionPerformed
    botones(true, false, false, false);
    inicializar(true, true);
    panelrecibo(false);
    panelcliente(true, true, false, false,false);
    
    }//GEN-LAST:event_jButton_nuevoActionPerformed

    private void jButton_informesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_informesActionPerformed
botones(false, false, false,true);
    }//GEN-LAST:event_jButton_informesActionPerformed

    private void jButton_bucarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_bucarActionPerformed
        String recibo= JOptionPane.showInputDialog("<html><font='Arial' size=+1>Ingrese el numero del recibo a buscar</font></html>");
        botones(false, true, false, false);    // TODO add your handling code here:
    }//GEN-LAST:event_jButton_bucarActionPerformed

    private void jButton_imprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_imprimirActionPerformed
    botones(false, false, true, false);    // TODO add your handling code here:
    }//GEN-LAST:event_jButton_imprimirActionPerformed

    private void jButton_confirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_confirmarActionPerformed
       modeloDeMiJTable.addRow(new Object[]{jTextField_codigo.getText(),jComboBox_codigo.getSelectedItem().toString(),"NA",jTextField_concepto.getText(),jTextField_valor.getText(),jComboBox_nit.getSelectedItem()});
       jButton_confirmar1.setVisible(true);
    }//GEN-LAST:event_jButton_confirmarActionPerformed

    private void jComboBox_destinoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox_destinoItemStateChanged
        destino=jComboBox_destino.getSelectedIndex();
    }//GEN-LAST:event_jComboBox_destinoItemStateChanged

    private void jTextField_codigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField_codigoActionPerformed
     if(destino==1){
        conn.establecer_conexion();
        String consulta="select nombres, direccion_casa,saldo from inquilinos where codigo='"+jTextField_codigo.getText()+"'";
        ResultSet n=conn.consulta(consulta);
        try{
        while(n.next()){
        jTextField_nombre.setText(n.getString(1));
        jTextField_direccion.setText(n.getString(2));
        jTextField_saldo.setText(n.getString(3));
        panelrecibo(true);
        jButton_confirmar.setVisible(true);
        }
        }
        catch(Exception e){}
     }   
    }//GEN-LAST:event_jTextField_codigoActionPerformed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
       jTextField_valor.setText(jTextField_saldo.getText());
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void jButton_confirmar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_confirmar1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton_confirmar1ActionPerformed

    /**
     * @param args the command line arguments
     */
    
    int[] anchos = {40, 200, 50};
    int destino=0;
    Conexion conn = new Conexion();
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup efecheque;
    private javax.swing.ButtonGroup extint;
    private javax.swing.JButton jButton_bucar;
    private javax.swing.JButton jButton_confirmar;
    private javax.swing.JButton jButton_confirmar1;
    private javax.swing.JButton jButton_imprimir;
    private javax.swing.JButton jButton_informes;
    private javax.swing.JButton jButton_nuevo;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JComboBox jComboBox_codigo;
    private javax.swing.JComboBox jComboBox_destino;
    private javax.swing.JComboBox jComboBox_nit;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton jRadioButton_cheque;
    private javax.swing.JRadioButton jRadioButton_efectivo;
    private javax.swing.JRadioButton jRadioButton_externo;
    private javax.swing.JRadioButton jRadioButton_interno;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField_codigo;
    private javax.swing.JTextField jTextField_concepto;
    private javax.swing.JTextField jTextField_direccion;
    private javax.swing.JTextField jTextField_nombre;
    private javax.swing.JTextField jTextField_saldo;
    private javax.swing.JTextField jTextField_valor;
    // End of variables declaration//GEN-END:variables
}
